package com.gzr.demo01.threadestate;

//线程优先级
//优先级低只是意味着获得调度的概率低.并不是优先级低就不会被调用了.这都是看CPU的调度
public class TestPriority {
    public static void main(String[] args) {
        System.out.println(Thread.currentThread().getName()+"===>"+Thread.currentThread().getPriority());

        MyPriority myPriority = new MyPriority();
        Thread t1 = new Thread(myPriority);
        Thread t2 = new Thread(myPriority);
        Thread t3 = new Thread(myPriority);
        Thread t4 = new Thread(myPriority);

        t1.start();

        t2.setPriority(2);
        t2.start();

        //设置最大优先级
        t3.setPriority(Thread.MAX_PRIORITY);
        t3.start();

        t4.setPriority(9);
        t4.start();
    }
}

class MyPriority implements Runnable{
    @Override
    public void run() {
        System.out.println(Thread.currentThread().getName()+"===>"+Thread.currentThread().getPriority());
    }
}
